<!--#
layout("/layouts/platform.html"){
#-->
<style>
    .el-upload input[type=file] {
        display: none;
    }

    .el-upload__text {
        color: #606266;
        font-size: 14px;
        text-align: center;
    }
</style>
<div id="app" v-cloak>
        <el-row class="header navbar ">
            <div class="btn-group tool-button mt5">
                <el-input placeholder="请输入内容" v-trim v-model="pageForm.searchKeyword" @keyup.enter.native="doSearch">
                    <el-select v-trim v-model="pageForm.searchName" slot="prepend" placeholder="查询类型" style="width: 120px;">
                        <el-option label="用户名" value="loginname"></el-option>
                        <el-option label="姓名" value="username"></el-option>
                        <el-option label="手机" value="mobile"></el-option>
                        <el-option label="邮箱" value="email"></el-option>
                    </el-select>
                    <el-button slot="append" icon="el-icon-search" @click="doSearch"></el-button>
                </el-input>
            </div>
            <!--<div class="pull-right offscreen-right mt5">
                <el-button size="medium" @click="batchCommand({type:'export'})">导出XLS</el-button>
            </div>-->
            <div class="pull-right offscreen-right" style="margin-right: 20px;line-height: 50px;">
                <el-tooltip class="item" effect="dark" content="导出EXCEL" placement="top">
                    <el-button circle icon="el-icon-download" size="mini" @click="batchCommand({type:'export'})"/>
                </el-tooltip>
            </div>
        </el-row>
        <el-row class="el-table-container">
            <el-table
                    :data="tableData" border
                    @sort-change='pageOrder'
                    size="small"
                    header-align="center"
                    style="width: 100%"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column type="expand" label="展开">
                    <template slot-scope="scope">
                        <el-form label-position="left" inline class="el-table-expand" size="mini">
                            <el-row :span="24">
                                <el-col :span="6">
                                    <el-form-item label="学校">
                                        <span>{{ scope.row.school }}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item label="专业">
                                        <span>{{ scope.row.major }}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item label="学历">
                                        <span>{{ scope.row.qualification }}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item  label="手机号">
                                        <span>{{ scope.row.mobile }}</span>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="邮箱">
                                        {{ scope.row.email }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item  label="签名">
                                        <div class="block" >
                                            <el-image
                                                    style="max-width: 200px"
                                                    :src="baseUrl+scope.row.fileId+'&time='+ Date.now()"
                                                    fit="cover ">
                                                <div slot="error" style="width: 80px; height: 80px" class="image-slot">
                                                    无签名
                                                </div>
                                            </el-image>
                                        </div>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </template>
                </el-table-column>
                <el-table-column
                        sortable
                        prop="loginname"
                        label="用户名"
                        header-align="center">
                </el-table-column>
                <el-table-column
                        prop="username"
                        label="姓名"
                        header-align="center"
                        :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column
                        prop="unit"
                        label="所属单位"
                        header-align="center"
                        align="center"
                        :show-overflow-tooltip="true"
                >
                    <template slot-scope="scope">
                        <span v-if="scope.row.unit!=null">
                            {{scope.row.unit.name}}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column
                        sortable
                        prop="disabled"
                        label="帐号状态"
                        header-align="center"
                        align="center"
                        :show-overflow-tooltip="true"
                >
                    <template slot-scope="scope">
                        <i v-if="scope.row.disabled" class="fa fa-circle text-danger ml5"></i>
                        <i v-if="!scope.row.disabled" class="fa fa-circle text-success ml5"></i>
                    </template>
                </el-table-column>
                <!--<el-table-column
                        sortable
                        prop="userOnline"
                        label="在线状态"
                        header-align="center"
                        align="center"
                        :show-overflow-tooltip="true"
                >
                    <template slot-scope="scope">
                        <i v-if="scope.row.userOnline" class="text-success ml5">在线</i>
                        <i v-if="!scope.row.userOnline" class="text-danger ml5">离线</i>
                    </template>
                </el-table-column>-->
                <el-table-column
                        prop="userOnline"
                        label="操作"
                        width="120">
                    <template slot-scope="scope">

                        <el-button size="mini" @click="dropdownCommand({type:'detail',id:scope.row.id})">详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-row>
        <el-row class="el-pagination-container">
            <el-pagination
                    @size-change="pageSizeChange"
                    @current-change="pageNumberChange"
                    :current-page="pageForm.pageNumber"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="pageForm.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageForm.totalCount">
            </el-pagination>
        </el-row>
    <el-dialog :close-on-click-modal="false"
            title="新建用户"
            :visible.sync="addDialogVisible"
            width="40%">
        <el-form :model="formData" ref="addForm" :rules="formRules" size="small" label-width="80px">
            <el-row :span="24">
                <el-col :span="12">
                    <el-form-item class="is-required" prop="parentUnit" label="所属单位" label-width="80px">
                        <el-cascader
                                style="width: 100%"
                                tabindex="1"
                                :options="unitTreeData"
                                v-trim v-model="parentUnit"
                                :fetch-suggestions="unitQuery"
                                @active-item-change="unitChange"
                                @change="unitChange2"
                                @select="unitSelect"
                                placeholder="请选择单位"
                        ></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="loginname" label="用户名">
                        <el-input maxlength="100" placeholder="用户名"
                                  v-trim v-model="formData.loginname"
                                  auto-complete="off" tabindex="2" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="username" label="姓名">
                        <el-input maxlength="20" placeholder="姓名"
                                  v-trim v-model="formData.username"
                                  auto-complete="off" tabindex="3" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="password" label="登录密码">
                        <el-input maxlength="20" placeholder="登录密码" v-trim v-model="formData.password"
                                  auto-complete="off" tabindex="4" type="password"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="passwordAgain" label="确认密码">
                        <el-input maxlength="20" placeholder="再输一次密码"
                                  v-trim v-model="formData.passwordAgain"
                                  auto-complete="off" tabindex="5" type="password"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item  label="审核权限">
                        <el-radio-group v-model="formData.audit">
                            <el-radio label="0">无</el-radio>
                            <el-radio label="1">审核人</el-radio>
                            <el-radio label="2">批准人</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item  label="角色">
                        <el-cascader v-model="formData.rolesIds" :options="roleOptions" :props="props" ref="cascader1" style="width:180px;"></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="mobile" label="手机号码">
                        <el-input maxlength="20" placeholder="手机号码"
                                  v-trim v-model="formData.mobile"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="email" label="邮箱">
                        <el-input maxlength="100" placeholder="邮箱"
                                  v-trim v-model="formData.email"
                                  auto-complete="off" tabindex="7" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="disabled" label="启用状态">
                        <el-switch
                                v-trim v-model="formData.disabled"
                                active-color="#ff4949"
                                inactive-color="#13ce66">
                        </el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="school" label="学校">
                        <el-input maxlength="20" placeholder="学校"
                                  v-trim v-model="formData.school"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="major" label="专业">
                        <el-input maxlength="16" placeholder="专业"
                                  v-trim v-model="formData.major"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="qualification" label="学历">
                        <el-input maxlength="16" placeholder="学历"
                                  v-trim v-model="formData.qualification"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="签名照">
                        <!--新建新建新建新建新建新建新建新建新建新建-->
                        <el-upload
                                class="upload-demo"
                                :drag="isDrag"
                                action="${base}/open/file/upload/file1"
                                name="Filedata"
                                :before-upload="beforeUpload"
                                :on-success="function(resp,file,fileList){return handleSuccess(resp,file,fileList)}"
                                :on-progress="uploadFileProcess"
                                style="height:180px;"
                                :limit="1"
                                :on-remove="handleRemove"
                                :file-list="fileList"
                                list-type="picture"
                        >
                            <i class="el-icon-upload" v-if="!formData.fileId|| formData.fileId==''"></i>
                            <div class="el-upload__text" v-if="!formData.fileId|| formData.fileId==''">将文件拖到此处，或<em>点击上传</em></div>
                            <el-progress v-if="fileUploadFlag == true" type="circle" :percentage="fileUploadPercent" style="margin-top:20px;"></el-progress>
                        </el-upload>
                        <div  v-if="!formData.fileId|| formData.fileId==''" >
                            1、只能上传 .png 文件，
                            2、文件不可直接改后缀名，需要另存为png格式，否则word无法识别，
                            3、不超过300kb
                            4、建议图片最小尺寸为240*100左右，或它锁定横竖比例大小，注意图片太大会影响报告中加入电子签名的速度。
                        </div>
                        <!--<div v-if="formData.signatureImage && formData.signatureImage.fileSize>0" style="color: green;font-size: 14px;">
                            文件名: {{formData.signatureImage.fileBeforeName}} &nbsp; &nbsp; 文件大小: {{(formData.signatureImage.fileSize/1024/1024).toFixed(2)}}MB
                        </div>-->
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="相关证书">
                        <el-upload
                                class="upload-demo"
                                name="Filedata"
                                action="${base}/open/file/upload/file1"
                                :on-remove="fileHandleRemove"
                                :before-remove="fileBeforeRemove"
                                :on-success="fileHandleSuccess"
                                multiple
                                :limit="10"
                                :on-exceed="fileHandleExceed"
                                :file-list="filesList">
                            <el-button size="small" type="primary">点击上传</el-button>
                        </el-upload>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
                    <el-button @click="addDialogVisible = false;fileList=[];filesList=[]">取 消</el-button>
                    <el-button type="primary" @click="doAdd">确 定</el-button>
                  </span>
    </el-dialog>
    <el-dialog :close-on-click-modal="false"
            title="编辑用户"
            :visible.sync="editDialogVisible"
            width="40%">
        <el-form :model="formData" ref="editForm" :rules="editRules" size="small" label-width="80px">
            <el-row :span="24">
                <el-col :span="12">
                    <el-form-item class="is-required" prop="parentUnit" label="所属单位" label-width="80px">
                        <el-cascader
                                style="width: 100%"
                                tabindex="1"
                                :options="unitTreeData"
                                v-trim v-model="parentUnit"
                                :fetch-suggestions="unitQuery"
                                @active-item-change="unitChange"
                                @change="unitChange2"
                                @select="unitSelect"
                                placeholder="请选择单位"
                        ></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="loginname" label="用户名">
                        <el-input maxlength="100" placeholder="用户名"
                                  v-trim v-model="formData.loginname"
                                  auto-complete="off" tabindex="2" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="username" label="姓名">
                        <el-input maxlength="20" placeholder="姓名"
                                  v-trim v-model="formData.username"
                                  auto-complete="off" tabindex="3" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item  label="审核权限">
                        <el-radio-group v-model="formData.audit">
                            <el-radio label="0">无</el-radio>
                            <el-radio label="1">审核人</el-radio>
                            <el-radio label="2">批准人</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item  label="角色">
                        <el-cascader v-model="formData.rolesIds" :options="roleOptions" :props="props" ref="cascader2" style="width:180px;"></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="mobile" label="手机号码">
                        <el-input maxlength="20" placeholder="手机号码"
                                  v-trim v-model="formData.mobile"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="email" label="邮箱">
                        <el-input maxlength="100" placeholder="邮箱"
                                  v-trim v-model="formData.email"
                                  auto-complete="off" tabindex="7" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="disabled" label="启用状态">
                        <el-switch
                                v-trim v-model="formData.disabled"
                                active-color="#ff4949"
                                inactive-color="#13ce66">
                        </el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="school" label="学校">
                        <el-input maxlength="20" placeholder="学校"
                                  v-trim v-model="formData.school"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="major" label="专业">
                        <el-input maxlength="16" placeholder="专业"
                                  v-trim v-model="formData.major"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="qualification" label="学历">
                        <el-input maxlength="16" placeholder="学历"
                                  v-trim v-model="formData.qualification"
                                  auto-complete="off" tabindex="6" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="签名照">
                        <!--修改修改修改修改修改修改修改修改修改-->
                        <el-upload
                                class="upload-demo"
                                action="${base}/open/file/upload/file1"
                                name="Filedata"
                                :drag="isDrag"
                                :before-upload="beforeUpload"
                                :on-success="function(resp,file,fileList){return handleSuccess(resp,file,fileList)}"
                                :on-progress="uploadFileProcess"
                                style="height:180px;"
                                :on-remove="handleRemove"
                                :file-list="fileList"
                                :limit="1"
                                list-type="picture"
                        >
                            <i class="el-icon-upload" v-if="!formData.fileId || formData.fileId==''"></i>
                            <div class="el-upload__text" v-if="!formData.fileId|| formData.fileId==''">
                                将文件拖到此处，或<em>点击上传</em>
                            </div>
                            <el-progress v-if="fileUploadFlag == true" type="circle" :percentage="fileUploadPercent" style="margin-top:20px;"></el-progress>
                        </el-upload>
                        <div  v-if="!formData.fileId|| formData.fileId==''" >
                            1、只能上传 .png 文件，
                            2、文件不可直接改后缀名，需要另存为png格式，否则word无法识别，
                            3、不超过300kb
                            4、建议图片最小尺寸为240*100左右，或它锁定横竖比例大小，注意图片太大会影响报告中加入电子签名的速度。
                        </div>
                 <!--       <div v-if="!formData.fileId && formData.signatureImage && formData.signatureImage.fileSize>0" style="color: green;font-size: 14px;">
                            文件名: {{formData.signatureImage.fileBeforeName}} &nbsp; &nbsp; 文件大小: {{(formData.signatureImage.fileSize/1024/1024).toFixed(2)}}MB
                        </div>-->
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="相关证书">
                        <el-upload
                                class="upload-demo"
                                name="Filedata"
                                action="${base}/open/file/upload/file1"
                                :on-remove="fileHandleRemove"
                                :before-remove="fileBeforeRemove"
                                :on-success="fileHandleSuccess"
                                multiple
                                :limit="10"
                                :on-exceed="fileHandleExceed"
                                :file-list="filesList">
                            <el-button size="small" type="primary">点击上传</el-button>
                        </el-upload>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>

        <span slot="footer" class="dialog-footer">
                    <el-button @click="editDialogVisible = false;fileList=[];filesList=[]">取 消</el-button>
                    <el-button type="primary" @click="doEdit">确 定</el-button>
                  </span>
    </el-dialog>


    <el-dialog :close-on-click-modal="false"
               title="查看用户"
               :visible.sync="detailDialogVisible"
               width="40%">
        <el-form :model="formData" ref="detailForm" size="small" label-width="80px">
            <el-row :span="24">
                <el-col :span="12">
                    <el-form-item  label="所属单位" label-width="80px" v-if="formData.unit">
                        {{formData.unit.name}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="loginname" label="用户名">
                        {{formData.loginname}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="username" label="姓名">
                        {{formData.username}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item  label="审核权限">
                        <span v-if="formData.audit==0">无<br/></span>
                        <span v-if="formData.audit==1">审核人<br/></span>
                        <span v-if="formData.audit==2">批准人<br/></span>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="mobile" label="手机号码">
                        {{formData.mobile}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="email" label="邮箱">
                        {{formData.email}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="disabled" label="启用状态">
                        <el-switch readonly disabled
                                v-trim v-model="formData.disabled"
                                active-color="#ff4949"
                                inactive-color="#13ce66">
                        </el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="school" label="学校">
                        {{formData.school}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="major" label="专业">
                        {{formData.major}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="qualification" label="学历">
                        {{formData.qualification}}
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="签名照">
                        <div class="block" >
                            <el-image
                                    style="max-width: 200px;"
                                    :src="baseUrl+formData.fileId+'&time='+ Date.now()"
                                    fit="cover ">
                                <div slot="error" style="width: 80px; height: 80px" class="image-slot">
                                    无签名
                                </div>
                            </el-image>
                        </div>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="相关证书">
                        <template v-for="item in filesList">
                            <el-link :href="AppFile+item.response.data.filePath" target="_blank">{{item.name}}</el-link><br>
                        </template>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>

        <span slot="footer" class="dialog-footer">
                    <el-button @click="detailDialogVisible = false;fileList=[];filesList=[]">关 闭</el-button>
                  </span>
    </el-dialog>
    <el-dialog :close-on-click-modal="false"
            :title="roleDialogTitle"
            :visible.sync="roleDialogVisible"
            width="70%">
        <el-table :data="roleTableData" style="width: 100%" size="small"
                  :highlight-current-row="true" row-key="id" lazy
                  :load="loadRoleChild">
            <el-table-column label="菜单名称" header-align="center" prop="name"
                             width="200" :show-overflow-tooltip="true" align="left">

            </el-table-column>

            <el-table-column label="URL" header-align="center" prop="href"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="资源类型" header-align="center" prop="type"
                             :show-overflow-tooltip="true" align="center">

                <template slot-scope="scope">
                    <i v-if="scope.row.type=='menu'" style="font-weight: bold">菜单</i>
                    <i v-if="scope.row.type=='data'">数据</i>
                </template>
            </el-table-column>

            <el-table-column label="权限标识" header-align="center" prop="permission"
                             :show-overflow-tooltip="true">
            </el-table-column>

        </el-table>
        <span slot="footer" class="dialog-footer">
                    <el-button @click="roleDialogVisible = false">关 闭</el-button>
                  </span>
    </el-dialog>
</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            var self = this;
            var validateLoginname = function (rule, value, callback) {
                var regex = new RegExp("^[a-zA-Z][a-zA-Z0-9_]{1,19}$");
                if (!regex.test(value)) {
                    callback(new Error('用户名以字母开头2-20字,允许使用字母/数字/下划线'));
                } else {
                    callback();
                }
            };
            var validatePass = function (rule, value, callback) {
                if (value !== self.formData.password) {
                    callback(new Error('两次输入密码不一致!'));
                } else {
                    callback();
                }
            };
            var validateUnit = function (rule, value, callback) {
                if (self.parentUnit.length < 1 || self.parentUnit[self.parentUnit.length - 1] == "") {
                    callback(new Error('请选择所属单位!'));
                } else {
                    callback();
                }
            };
            return {
                AppFile:"${AppFileDomain}${AppUploadBase}",
                addDialogVisible: false,
                editDialogVisible: false,
                detailDialogVisible:false,
                roleDialogVisible: false,
                fileList:[],
                filesList:[],
                isDrag:true,
                baseUrl:"${base}/open/file/view/image?param=",
                treeData: {
                    label: 'name',
                    children: 'zones',
                    id: 'id',
                    isLeaf: 'leaf'
                },
                tableData: [],
                /*options: [],*/
                parentUnit: [],
                pageForm: {
                    searchUnit: "",
                    searchName: "",
                    searchKeyword: "",
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    pageOrderName: "",
                    pageOrderBy: ""
                },
                formData: {
                    id: "",
                    unitid: "",
                    disabled: false,
                    signatureImage:{
                        infoType:"signature",
                        fileSize: 0,
                        fileType:"",
                        fileBeforeName:"",
                        fileName:"",
                        filePath: "",
                        fileUrl:""
                    },
                    audit:"0"
                },
                fileUploadFlag:false,//是否正在上传
                fileUploadPercent:0,
                formRules: {
                    parentUnit: [
                        {validator: validateUnit, trigger: ['blur', 'change']}
                    ],
                    loginname: [
                        {required: true, message: '用户名', trigger: ['blur', 'change']},
                        {validator: validateLoginname, trigger: ['blur', 'change']}
                    ],
                    username: [
                        {required: true, message: '姓名', trigger: ['blur', 'change']}
                    ],
                    email: [
                        {required: false, message: '邮箱地址', trigger: ['blur', 'change']},
                        {type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change']}
                    ],
                    mobile: [
                        {required: false, message: '手机号码', trigger: ['blur', 'change']},
                        {pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码'}
                    ],
                    password: [
                        {required: true, message: '请输入密码', trigger: ['blur', 'change']},
                        {min: 3, max: 20, message: '密码长度必须是3-20位', trigger: 'change'}
                    ],
                    passwordAgain: [
                        {required: true, message: '请再次输入新密码', trigger: ['blur', 'change']},
                        {validator: validatePass, trigger: 'change'}
                    ],
                    rolesIds:[
                        {required: true, message: '角色', trigger: ['blur', 'change']}
                    ]
                },
                editRules: {
                    username: [
                        {required: true, message: '姓名', trigger: ['blur', 'change']}
                    ],
                    email: [
                        {required: false, message: '邮箱地址', trigger: ['blur', 'change']},
                        {type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change']}
                    ],
                    mobile: [
                        {required: false, message: '手机号码', trigger: ['blur', 'change']},
                        {pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码'}
                    ],
                    rolesIds:[{required: true, message: '角色', trigger: ['blur', 'change']}]
                },
                roleDialogTitle: "查看用户权限",
                roleTableData: [],//treeTable后台取出的数据
                userId: "",//当前用户ID
                multipleSelection: [],
                props: { multiple: true },
                roleOptions:[],
                unitTreeData:[]
            }
        },
        methods: {

            beforeUpload: function (file) {
                var isLt5M = file.size / 1024 / 1024 < 0.3;
                console.log(file.size / 1024 / 1024)
                var type= file.name.substring(file.name.lastIndexOf("."), file.name.length);
                this.$set(this.formData.signatureImage, "fileBeforeName",file.name);
                if (!(type==".png")) {
                    this.$message.error('只可上传png格式图片');
                    return false;
                }
                if (!isLt5M) {
                    this.$message.error('文件大小不能超过300kb');
                    return false;
                }
                return true;
            },
            handleRemove:function(file, fileList){
                /*this.formData.signatureImage={
                    infoType:"signature",
                    fileSize: 0,
                    fileType:"",
                    fileBeforeName:"",
                    fileName:"",
                    filePath: "",
                    fileUrl:""
                }
                this.$set(this.formData.signatureImage, "fileSize", 0);
                this.$set(this.formData.signatureImage, "filePath", "");
                this.$set(this.formData.signatureImage, "fileType", "");
                this.$set(this.formData.signatureImage, "fileUrl", "");
                this.$set(this.formData.signatureImage, "fileName", "");*/
                this.$set(this, "isDrag", true);
                this.formData.fileId = "";
                this.fileList=[];
            },
            handleSuccess: function (response, file, fileList) {
                if (response.code == 0) {
                    // 对象属性直接赋值不会触发试图更新，采用 Vue.set 、this.$set或者Object.assign({}，this.obj)创建新对象
                    // 或者也可以定义一个 refresh 属性 ，当数据发生改变时，该属性同时变化，也会触发视图更新
                    /*this.$set(this.formData.signatureImage, "fileSize", response.data.file_size);
                    this.$set(this.formData.signatureImage, "filePath", response.data.file_path);
                    this.$set(this.formData.signatureImage, "fileType", response.data.file_type);
                    this.$set(this.formData.signatureImage, "fileUrl", response.data.file_url);
                    this.$set(this.formData.signatureImage, "fileName", response.data.file_name);
                    if (this.formData.signatureImage && this.formData.signatureImage.fileSize>0){
                        var fileInfo={name: this.formData.signatureImage.fileBeforeName, url: this.baseUrl+this.formData.signatureImage.filePath};
                        this.fileList.push(fileInfo);
                    }*/
                    this.formData.fileId = response.data.id;
                    this.isDrag=false;
                } else {
                    this.$message({
                        message: response.msg,
                        type: 'error'
                    });
                    /*this.$set(this.formData.signatureImage, "fileSize", 0);
                    this.$set(this.formData.signatureImage, "filePath", "");
                    this.$set(this.formData.signatureImage, "fileType", "");
                    this.$set(this.formData.signatureImage, "fileUrl", "");
                    this.$set(this.formData.signatureImage, "fileName", "");*/
                    this.formData.fileId = "";
                    this.fileList=[];
                }
                this.fileUploadFlag=false;
            },
            //进度条
            uploadFileProcess:function(event, file, fileList){
                this.fileUploadFlag=true;
                this.fileUploadPercent = parseInt(event.percent);
            },

            //级联选择器从后台动态获取下级数据
            loadTree: function (val, cb) {
                var url = base + "/platform/sys/unit/tree";
                $.post(url, {pid: val}, function (data) {
                    if (data.code == 0) {
                        cb(data.data);
                    }
                }, "json");
            },
            initTree: function () {
                var self = this;
                this.loadTree("", function (val) {
                    self.options = val;
                });
            },
            unitQuery: function (queryString, cb) {
                //cb(this.options);
            },
            unitSelect: function (val) {
            },
            unitTree: function (table, data, pid) {//树形数据的级联查找很是头疼
                var self = this;
                table.findIndex(function (obj) {
                    if (pid == obj.value) {
                        obj.children = data;
                    } else if (obj.children && obj.children.length > 0) {
                        self.unitTree(obj.children, data, pid);
                    }
                });
            },
            unitChange2:function(val){
                /*var self = this;
                if(val[0]=="root"){
                    self.parentUnit=[];
                }*/
            },
            unitChange: function (val) {
                /*var self = this;
                self.parentUnit = val;
                var pid = val[val.length - 1];
                this.loadTree(pid, function (tree) {
                    self.unitTree(self.options, tree, pid);
                });*/
            }, pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/sys/user/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm");
                return "";
            },
            doSearch: function () {
                /*this.pageForm.searchUnit = this.parentUnit[this.parentUnit.length - 1];
                this.pageForm.searchUnit ="";*/
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            listFile:function(){
                var self = this;
                self.fileList=[];
                if (self.formData.signatureImage){
                    var fileInfo={name: self.formData.signatureImage.fileBeforeName, url: self.baseUrl+self.formData.fileId};
                    self.fileList.push(fileInfo);
                    //self.isDrag=false;
                    self.$set(this, "isDrag", false);
                }else {
                    self.formData.signatureImage={
                            infoType:"signature",
                            fileSize: 0,
                            fileType:"",
                            fileBeforeName:"",
                            fileName:"",
                            filePath: "",
                            fileUrl:""
                    }
                }
            },
            openEdit:function(){
                var self = this;
                self.isDrag=true;
                self.fileList=[];
                self.filesList=[];
                self.parentUnit=[];
                this.formData = {
                    id: "",
                    unitid: "",
                    disabled: false,
                    signatureImage:{
                        infoType:"signature",
                        fileSize: 0,
                        fileType:"",
                        fileBeforeName:"",
                        fileName:"",
                        filePath: "",
                        fileUrl:""
                    },
                    audit:"0"
                };//打开新增窗口,表单先清空
                if (this.$refs["editForm"])
                    this.$refs["editForm"].resetFields();
                this.editDialogVisible = true;
            },
            openAdd: function () {
                var self = this;
                self.fileList=[];
                self.filesList=[];
                self.parentUnit=[];
                self.isDrag=true;
                self.formData = {
                    id: "",
                    unitid: "",
                    disabled: false,
                    signatureImage:{
                        infoType:"signature",
                        fileSize: 0,
                        fileType:"",
                        fileBeforeName:"",
                        fileName:"",
                        filePath: "",
                        fileUrl:""
                    },
                    audit:"0"
                };//打开新增窗口,表单先清空
                var role = '10eca5ecb3824284bf9d22ab2cd51dbb';
                self.formData.rolesIds = role.split(",");
                if (self.$refs["addForm"])
                    self.$refs["addForm"].resetFields();
                self.addDialogVisible = true;
            },
            doAdd: function () {
                var self = this;
                if(!self.formData.rolesIds||self.formData.rolesIds.length==0){
                    self.$message({
                        message: '至少保留一个角色',
                        type: 'error'
                    });
                    return ;
                }
                if (self.fileUploadFlag){
                    self.$message({
                        message: "文件正在上传，请稍等！",
                        type: 'warning'
                    });
                    return;
                }else {
                    self.$refs["addForm"].validate(function (valid) {
                        if (valid) {
                            self.formData.unitid = self.parentUnit[self.parentUnit.length - 1]||"";
                            if(self.formData.rolesIds){
                                self.formData.rolesIds = self.formData.rolesIds.join(",")
                            }
                            $.post(base + "/platform/sys/user/addDo",{userInfo: JSON.stringify(self.formData),rolesIds: self.formData.rolesIds}, function (data) {
                                if (data.code == 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.doSearch();//查询是带条件的,加载新建用户选择的单位用户数据
                                    self.fileList=[];
                                    self.filesList=[];
                                    //self.pageData();
                                    self.addDialogVisible = false;
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                    if(self.formData.rolesIds){
                                        self.formData.rolesIds = self.formData.rolesIds.split(",")
                                    }
                                }
                            }, "json");
                        }
                    });
                }
            },
            doEdit: function () {
                var self = this;
                if(!self.formData.rolesIds||self.formData.rolesIds.length==0){
                    self.$message({
                        message: '至少保留一个角色',
                        type: 'error'
                    });
                    return ;
                }
                self.$refs["editForm"].validate(function (valid) {
                    if (valid) {
                        self.formData.unitid = self.parentUnit[self.parentUnit.length - 1]||"";
                        if(self.formData.rolesIds){
                            self.formData.rolesIds = self.formData.rolesIds.join(",")
                        }
                        $.post(base + "/platform/sys/user/editDo",{userInfo: JSON.stringify(self.formData),rolesIds: self.formData.rolesIds}, function (data) {
                            if (data.code == 0) {
                                self.$message({
                                    message: data.msg,
                                    type: 'success'
                                });
                                self.doSearch();//查询是带条件的,加载新建用户选择的单位用户数据
                                self.fileList=[];
                                self.filesList=[];
                                //self.pageData();
                                self.editDialogVisible = false;
                            } else {
                                self.$message({
                                    message: data.msg,
                                    type: 'error'
                                });
                                if(self.formData.rolesIds){
                                    self.formData.rolesIds = self.formData.rolesIds.split(",")
                                }
                            }
                        }, "json");
                    }
                });
            },
            initRoleTreeTable: function () {
                var self = this;
                var url = base + "/platform/sys/user/menu/" + self.userId;
                $.post(url, {pid: ""}, function (data) {
                    if (data.code == 0) {
                        self.roleTableData = data.data;
                    }
                }, "json");

            },
            loadRoleChild: function (tree, treeNode, resolve) {
                var self = this;
                var url = base + "/platform/sys/user/menu/" + self.userId;
                $.post(url, {pid: tree.id}, function (data) {
                    if (data.code == 0) {
                        resolve(data.data);
                    }
                }, "json");
            },
            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                if ("role" == command.type) {
                    self.roleDialogVisible = true;
                    self.roleDialogTitle = "查看用户 " + command.loginname + " 的权限";
                    self.userId = command.id;
                    self.initRoleTreeTable();
                }
                if ("reset" == command.type) {
                    self.$confirm('确定重置用户 ' + command.loginname + ' 的密码', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/sys/user/resetPwd/" + command.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$alert('新密码为 ' + data.data, '新密码', {
                                            confirmButtonText: '确定'
                                        });
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
                if ("enable" == command.type || "disable" == command.type) {
                    $.post(base + "/platform/sys/user/" + command.type + "/" + command.id, {}, function (data) {
                        if (data.code == 0) {
                            self.$message({
                                message: data.msg,
                                type: 'success'
                            });
                            if ("disable" == command.type) {
                                command.row.disabled=true;
                            }
                            if ("enable" == command.type) {
                                command.row.disabled=false;
                            }
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                if ("detail" == command.type) {
                    $.post(base + "/platform/sys/user/detail/" + command.id, {}, function (data) {
                        if (data.code == 0) {
                            self.formData = data.data;//加载后台表单数据
                            self.setfileFile(self.formData.files)
                            self.detailDialogVisible=true
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                if ("edit" == command.type) {
                    $.post(base + "/platform/sys/user/edit/" + command.id, {}, function (data) {
                        if (data.code == 0) {
                            self.openEdit();
                            self.formData = data.data;//加载后台表单数据
                            var child = data.data.unitid.split(",");
                            var childs = "";
                            for(unit of child){
                                childs = childs+","+unit;
                                self.unitChange(childs.substring(1,childs.length).split(","));
                            }
                            self.parentUnit = child;
                            if(self.formData.rolesIds){
                                self.formData.rolesIds = self.formData.rolesIds.split(",")
                            }
                            self.setfileFile(self.formData.files)
                            self.listFile();
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                if ("delete" == command.type) {
                    self.$confirm('此操作将删除 ' + command.loginname, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/sys/user/delete/" + command.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
            },
            batchCommand: function (command) {
                var self = this;
                if ("delete" == command.type) {
                    if (self.multipleSelection.length == 0) {
                        self.$message({
                            message: "请选择要删除的用户",
                            type: 'warning'
                        });
                    } else {
                        var loginnames = [];
                        var ids = [];
                        var fileIds=[];
                        self.multipleSelection.forEach(function (val) {
                            loginnames.push(val.loginname);
                            ids.push(val.id);
                            fileIds.push(val.fileId);
                        });
                        self.$confirm('此操作将删除用户 ' + loginnames.toString(), '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning',
                            callback: function (a, b) {
                                if ("confirm" == a) {//确认后再执行
                                    $.post(base + "/platform/sys/user/delete", {ids: ids.toString(),fileIds:fileIds.toString()}, function (data) {
                                        if (data.code == 0) {
                                            self.$message({
                                                message: data.msg,
                                                type: 'success'
                                            });
                                            self.doSearch();
                                        } else {
                                            self.$message({
                                                message: data.msg,
                                                type: 'error'
                                            });
                                        }
                                    }, "json");
                                }
                            }
                        });
                    }
                }
                if ("export" == command.type) {
                    window.open(base + "/platform/sys/user/export?searchUnit=" + self.pageForm.searchUnit
                        + "&searchName=" + self.pageForm.searchName
                        + "&searchKeyword=" + self.pageForm.searchKeyword
                        + "&pageOrderName=" + self.pageForm.pageOrderName
                        + "&pageOrderBy=" + self.pageForm.pageOrderBy
                    );
                }
            },
            handleSelectionChange: function (val) {
                this.multipleSelection = val;
            },
            getRoleOptions(){
                var self = this;
                $.post(base + "/platform/sys/role/roleTree", {}, function (data) {
                    if (data.code == 0) {
                        self.roleOptions = data.data;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doUnitTreeDataLoad: function () {
                var self = this;
                $.post(base + "/platform/sys/unit/treeAll", {}, function (data) {
                    if (data.code == 0) {
                        self.unitTreeData = data.data;
                    }
                }, "json");
            },
            handleUnitClick:function(data){
                this.pageForm.searchUnit=data.value
                this.doSearch();
            },

            fileHandleRemove: function (file, fileList) {
                var self = this;
                var thisData = file.response.data;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/open/file/upload/delFile/"+thisData.id, {}, function (data) {
                    if (data.code == 0) {
                        sublime.closeLoadingbar();//关闭loading
                        self.$message({message: data.msg,type: 'success'});
                        if(self.formData.files && self.formData.files!=""){
                            if(self.formData.files.split(",").length>1){
                                self.formData.files = self.formData.files.replace(","+thisData.id,"");
                            }else{
                                self.formData.files = "";
                            }
                        }
                    } else {
                        self.$message({message: data.msg,type: 'error'});
                    }
                }, "json");
            },
            fileHandleExceed: function (files, fileList) {
                this.$message.warning(`当前限制选择 10 个文件，本次选择了 `+files.length+` 个文件，共选择了 `+(files.length + fileList.length)+` 个文件`);
            },
            fileBeforeRemove: function (file) {
                return this.$confirm(`确定移除 `+file.name+`？`);
            },
            fileHandleSuccess:function(file){
                if(this.formData.files && this.formData.files!=""){
                    this.formData.files += ","+file.data.id;
                }else{
                    this.formData.files = file.data.id;
                }
            },
            setfileFile: function (fileId) {
                var self = this;
                self.filesList=[];
                if(fileId && fileId!=""){
                    var fileIds = fileId.split(",")
                    for(var i=0;i<fileIds.length;i++){
                        $.post(base + "/open/file/upload/getFile/"+fileIds[i], {}, function (data) {
                            if (data.code == 0) {
                                var file = {
                                    name:data.data.fileBeforeName,
                                    response:{
                                        data:data.data
                                    }
                                }
                                self.filesList.push(file);
                            } else {
                                self.$message({message: data.msg,type: 'error'});
                            }
                        }, "json");
                    }

                }
            },
        },
        created: function () {
            //this.initTree();
            this.doSearch();
            this.getRoleOptions();
            this.doUnitTreeDataLoad();
        }
    });
</script>
<style>
</style>
<!--#
}
#-->
